﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
using PocoReport;
using Image=iTextSharp.text.Image;
using Paragraph=iTextSharp.text.Paragraph;

namespace TestApp
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //Document document = new Document();
            //using (FileStream stream = File.Create("C:\\PocoReport.pdf"))
            //{
            //    PdfWriter.GetInstance(document, stream);
            //    document.Open();
            //    try
            //    {
            //        Paragraph paragraph = new Paragraph();
            //        paragraph.Add(new Chunk("Some text"));
            //        paragraph.Add(new Chunk(Image.GetInstance(@"C:\Documents and Settings\Geoffrey\Desktop\Calendar.bmp"), 0, 0));
            //        paragraph.Add(new Chunk("Some more text"));
            //        document.Add(paragraph);
            //    }
            //    finally
            //    {
            //        document.Close();
            //    }
            //}
            //Process.Start("C:\\PocoReport.pdf");

            Report report = new Report();
            report.Load(File.OpenRead("..//..//TestReport3.xml"));
            using (FileStream stream = File.Create("C:\\PocoReport.pdf"))
            {
                Dictionary<string, object> dataSource = new Dictionary<string, object>();
                dataSource.Add("Order", new Order
                                            {
                                                CustomerName = "Test Customer",
                                                Date = DateTime.Now,
                                                Details = new List<OrderDetail>
                                                              {
                                                                  new OrderDetail
                                                                      {
                                                                          Description = "Night Vission Goggles",
                                                                          ItemPrice = 400
                                                                      },
                                                                  new OrderDetail
                                                                      {
                                                                          Description = "M16 Assault Rifle",
                                                                          ItemPrice = 700
                                                                      }
                                                              }
                                            });
                report.Generate(stream, dataSource);
            }
            Process.Start("C:\\PocoReport.pdf");
        }

        public class Order
        {
            public DateTime Date { get; set; }
            public string CustomerName { get; set; }
            public IList<OrderDetail> Details { get; set; }
        }

        public class OrderDetail
        {
            public string Description { get; set; }
            public double ItemPrice { get; set; }
            public byte[] Image { get { return File.ReadAllBytes(@"C:\Documents and Settings\Geoffrey\Desktop\Calendar.bmp"); } }
        }
    }
}
